<?php
	include_once "third_part/simple_html_dom.php";
	include_once "util/util.php";
	
	function get_ip_json($ip_str){
		
		$json_arr = array('location'=>'unknown',
		'service_company'=>'unknown');
		//http://www.ip138.com/ips138.asp?ip=124.204.171.29&action=2
		$baseurl = "http://www.ip138.com/ips138.asp?ip=".$ip_str."&action=2";
		//echo $baseurl;
		$contents = myfile_get_content($baseurl);
		//echo $contents;
		$html = str_get_html($contents);
		//$$(".ul1 li")[1]
		
		foreach($html->find('.ul1 li') as $info) {
			$text = $info->innertext;
			break;
		}
		//本站主数据：北京市
		
		$arr=explode(" ",substr($text,12));
		
		//print_r($arr);
		/*$json_arr['location'] = iconv("gb2312","utf-8",$arr[0]);
		$json_arr['service_company'] = iconv("gb2312","utf-8",$arr[1]);*/
		$json_arr['location'] = iconv("gb2312","utf-8",$arr[0]);
		$json_arr['service_company'] = iconv("gb2312","utf-8",$arr[1]);
		print_r($json_arr);
		
		$json_str = json_encode($json_arr);
		
		echo $json_str;
	}
	
	$ip_str = $_GET["ip_str"];
	get_ip_json($ip_str);
	
?>